/*
 * register.js
 */

$(document).ready(function(){
	
})

function checkRegisterInfo(){
	var username = document.getElementById("username");
	var email = document.getElementById("email");
	var password = document.getElementById("password");
	var confirmPassword = document.getElementById("confirmPassword");
	var cellphone = document.getElementById("cellphone");
	
	var phoneNumReg=/^([0-9]{11})?$/;
	var isValidPhoneNum=phoneNumReg.test(cellphone.value);
	
	var emailReg=/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
	var isValidEmail = emailReg.test(email.value);
	
	if(username.value != "" && email.value != "" && isValidEmail && password.value != "" 
		&& confirmPassword.value != "" && cellphone.value != "" && isValidPhoneNum 
		&& password.value == confirmPassword.value){
		$(".usernameWarning").text("");
		$(".passwordWarning").text("");
		$(".confirmPasswordWarning").text("")
		$(".emailWarning").text("");
		$(".cellphoneWarning").text("");
		return true;
	}
	
	if(username.value == ""){
		$(".usernameWarning").text("用户名不能为空");
		return false;
	}
	
	if(password.value.length <=5 || password.value.length > 16){
		$(".usernameWarning").text("");
		$(".passwordWarning").text("密码长度不正确");
		return false;
	}
	
	if(password.value != confirmPassword.value){
		$(".usernameWarning").text("");
		$(".passwordWarning").text("");
		$(".confirmPasswordWarning").text("两次输入的密码不相同")
		return false;
	}
	
	if(email.value == "" || !isValidEmail){
		$(".usernameWarning").text("");
		$(".passwordWarning").text("");
		$(".confirmPasswordWarning").text("")
		$(".emailWarning").text("邮箱地址不正确");
		return false;
	}
	
	if(cellphone.value == ""  || !isValidPhoneNum){
		$(".usernameWarning").text("");
		$(".passwordWarning").text("");
		$(".confirmPasswordWarning").text("")
		$(".emailWarning").text("");
		$(".cellphoneWarning").text("手机号码不正确");
		return false;
	}
}